import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CommandPage extends StatefulWidget {
  @override
  State<CommandPage> createState() => _CommandPageState();
}

class _CommandPageState extends State<CommandPage> {
  var listTiles = <ListTile>[];
  final List<Tab> myTabs = <Tab>[
    Tab(text: "测试"),
    Tab(
      text: "陈 直流",
    ),
    Tab(
      text: "陈 交流",
    )
  ];

  ///发送蓝牙数据
  void send(String msg) {
    setState(() {
      listTiles.add(ListTile(
        title: Text(DateTime.now().toString()),
        leading: const Icon(Icons.bluetooth_audio),
        subtitle: Text(msg),
      ));
    });
  }
  ///收到蓝牙数据
  void receive(String msg) {
    setState(() {
      listTiles.add(ListTile(
        title: Text(DateTime.now().toString()),
        leading: const Icon(Icons.phone_android),
        subtitle: Text(msg),
      ));
    });
  }
  ///清空数据
  void clean() {
    setState(() {
      listTiles.clear();
    });
  }

  ///信息
  void info(String msg){
    setState(() {
      listTiles.add(ListTile(
        title: Text(DateTime.now().toString()),
        leading: const Icon(Icons.info),
        subtitle: Text(msg),
      ));
    });
  }


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    // throw UnimplementedError();
    send("hello bluetooth");
    receive("hello flutter");
    info("建立数据库链接");
    return Column(
      children: [
        Container(
          height: 500,
          child: ListView(
            children: listTiles,
          ),
        )
      ],
    );
  }
}
